﻿//
// GNS_PopWndUserInfo.cpp
// MobileManageSys
//FuncTion 个人信息
// Created by mr.l on 16/1/12.
//
//

#include "GNS_PopWndUserInfo.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "GNS_PlayerMgr.h"
USING_NS_CC;
using namespace cocostudio::timeline;
using namespace ui;

#define winsize Director::getInstance()->getVisibleSize()

GNS_PopWndUserInfo::GNS_PopWndUserInfo()
{
    UserInfoNode=nullptr;
    pInfoMakeLayer=nullptr;
}

GNS_PopWndUserInfo::~GNS_PopWndUserInfo()
{
    
}

GNS_PopWndUserInfo* GNS_PopWndUserInfo::createLayer()
{
    auto pUserInfo = GNS_PopWndUserInfo::create();
    
    auto pScene = Director::getInstance()->getRunningScene();
    if (!pScene)
        return 0;
    pScene->addChild(pUserInfo);
    
    return pUserInfo;
}

bool GNS_PopWndUserInfo::init()
{
    if ( !GNS_YJFLayer::init() )
    {
        return false;
    }
    return true;
}

void GNS_PopWndUserInfo::SetNodeName(std::string CsbName)
{
    UserInfoNode = Loadcsb(CsbName);
    UserInfoNode->setPosition(Vec2(winsize.width/2, winsize.height/2));
    addChild(UserInfoNode,11);
    
    GNS_PlayerMgr::getInstance()->_NodeChildVec.pushBack(UserInfoNode);
    
    auto pBackBtn = static_cast<Button*>(UserInfoNode->getChildByName("UserInfoBackBtn"));
    pBackBtn->setTag(10);
    pBackBtn->addTouchEventListener(CC_CALLBACK_2(GNS_PopWndUserInfo::BtnCallBack, this));
    
    //添加遮罩
    //pInfoMakeLayer = GNS_MakeLayer::CreateMakeLayer("加载中...");
    //this->addChild(pInfoMakeLayer); //problems
}
void GNS_PopWndUserInfo::BtnCallBack(cocos2d::Ref *pSender, ui::Widget::TouchEventType type){
    if (type==ui::Widget::TouchEventType::ENDED) {
        auto pButton = (Button*)pSender;
        int BtnTag = pButton->getTag();
        switch (BtnTag) {
            case 10:
            {
                if (GNS_PlayerMgr::getInstance()->_NodeChildVec.size()!=0) {
                    GNS_PlayerMgr::getInstance()->_NodeChildVec.clear();
                     this->removeAllChildrenWithCleanup(true);
                     this->getParent()->removeChild(this);
                }
                //auto SystemNode=GNS_PlayerMgr::getInstance()->_NodeHallVec.at(0);
                //SystemNode->setVisible(true);

				GNS_NodeMgr::getInstance()->setMenuVisible("SystemMgr", true);
                break;
            }
            default:
                break;
        }
    }
}
void GNS_PopWndUserInfo::UserInfoDate(CMD_SC_GetMobileUserinfoResult  pUserInfoDate)
{
    auto pImage = static_cast<ImageView*>(UserInfoNode->getChildByName("UserID"));
    auto ptext = static_cast<Text*>(pImage->getChildByName("Text_1"));
    ptext->setString(StringUtils::format("%d",pUserInfoDate._agentCode));
    
    auto pImage0 = static_cast<ImageView*>(UserInfoNode->getChildByName("UserID_0"));
    auto ptext0 = static_cast<Text*>(pImage0->getChildByName("Text_1"));
    ptext0->setString(StringUtils::format("%d",pUserInfoDate._uplineCode));
    
    auto pImage1 = static_cast<ImageView*>(UserInfoNode->getChildByName("UserID_1"));
    auto ptext1 = static_cast<Text*>(pImage1->getChildByName("Text_1"));
    ptext1->setString(StringUtils::format("%d",pUserInfoDate._uplinePercent));
    
    auto pImage2 = static_cast<ImageView*>(UserInfoNode->getChildByName("UserID_2"));
    auto ptext2 = static_cast<Text*>(pImage2->getChildByName("Text_1"));
    ptext2->setString(StringUtils::format("%d",pUserInfoDate._selfPercent));
    
    auto pImage3 = static_cast<ImageView*>(UserInfoNode->getChildByName("UserID_3"));
    auto ptext3 = static_cast<Text*>(pImage3->getChildByName("Text_1"));
    ptext3->setString(StringUtils::format("%lld",pUserInfoDate._yesterPlayProfit));
    
    auto pImage4 = static_cast<ImageView*>(UserInfoNode->getChildByName("UserID_4"));
    auto ptext4 = static_cast<Text*>(pImage4->getChildByName("Text_1"));
    ptext4->setString(StringUtils::format("%lld",pUserInfoDate._yesterRevenue));
    
    auto pImage5 = static_cast<ImageView*>(UserInfoNode->getChildByName("UserID_5"));
    auto ptext5 = static_cast<Text*>(pImage5->getChildByName("Text_1"));
    ptext5->setString(StringUtils::format("%lld",pUserInfoDate._agentGold));
    
    auto pImage6 = static_cast<ImageView*>(UserInfoNode->getChildByName("UserID_6"));
    auto ptext6 = static_cast<Text*>(pImage6->getChildByName("Text_1"));
    ptext6->setString(StringUtils::format("%d",pUserInfoDate._lowlinePromoterNum));
    
    auto pImage7 = static_cast<ImageView*>(UserInfoNode->getChildByName("UserID_7"));
    auto ptext7 = static_cast<Text*>(pImage7->getChildByName("Text_1"));
    ptext7->setString(StringUtils::format("%d",pUserInfoDate._lowlineUserNum));
    
    /*pInfoMakeLayer->Show(false);*/

}
